package com.aaa.controller.back;

import com.aaa.entity.Dept;
import com.aaa.service.back.DeptService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RequestMapping("/dept")
@Controller
public class DeptController {

    @Resource
    private DeptService deptService;

    @RequestMapping("/findDept")
    public String findDept(Model model){
        List<Map<String, Object>> deptList = deptService.findDept();
        model.addAttribute("deptList",deptList);
        return "back/dept-list";
    }

    @RequestMapping("/addDeptShow")
    public String addDeptShow(){
        return "back/dept-add";
    }

    @RequestMapping("/addDeptSubmit")
    public String addDeptSubmit(Dept dept){
        deptService.addDept(dept);
        return "redirect:/dept/findDept";
    }

    @RequestMapping("/editDeptShow")
    public String editDeptShow(Integer deptId,Model model){
        Map<String, Object> deptMap = deptService.findByDeptId(deptId);
        model.addAttribute("deptMap",deptMap);
        return "back/dept-edit";
    }

    @RequestMapping("/editDeptSubmit")
    public String editDeptSubmit(Dept dept){
        deptService.editDept(dept);
        return "redirect:/dept/findDept";
    }
}
